<?php

 
class TesoreriaController extends Zend_Controller_Action
{

    public function init()
    {
        /* Initialize action controller here */
    }

    public function indexAction()
    {
        
    }
    
    /** Made by Alexander Choque **/
    
    public function cierrecajagenAction(){
		$pintar=new Libreria_Pintar();
		
		$login = new Zend_Session_Namespace('login');
	    
      	$val[]=array('#usuario',$login->user,'val');       
		
		$evt[] = array('#btnprocesar', 'click','cierrecajagenerallista("non");');
        
		$fechAct=date("d/m/Y");
		$val[] = array('#txtfecha1',$fechAct , 'val');
		$val[] = array('#txtfecha2',$fechAct , 'val');
		

    	$cboestados[0] = array('t', '1.Todos');
    	$cboestados[1] = array('A', '2.Activos');
    	$cboestados[2] = array('', '3.Anulados');
	    
	    $val[] = array('#cboestados', $pintar->ContenidoCombo($cboestados, '9999999999'), 'html');
        $val[] = array('#btnlistadototal', 'ListadoTotal', 'val');
        $val[] = array('#btnarchivo', 'Archivo', 'val');
    	
    	$cboreportes[0] = array('1', '1.Listado Total');
    	$cboreportes[1] = array('2', '2.Imprimir x Caja');
    	$cboreportes[2] = array('3', '3.Exportar a Excel');

	    $val[] = array('#cboreportes', $pintar->ContenidoCombo($cboreportes, '9999999999'), 'html');
        $val[] = array('#btnimprimirxcaja', 'Imprimir x Caja', 'val');

		$tablar =  '<table id="caja" class="tabla">';
		$tablar .= '<tr>';
		$tablar .= '<th width="50px">Item</th>';
		$tablar .= '<th width="50px">Nro.Recibo</th>';
		$tablar .= '<th width="40px">Fecha</th>';
		$tablar .= '<th width="40px">Hora</th>';
		$tablar .= '<th width="280px">Contribuyente</th>';
		$tablar .= '<th width="180px">Cajero</th>';
		$tablar .= '<th>Monto</th><th>Estado</th>';
		$tablar .= '<th>Tipo Pago</th>';
		$tablar .= '<th width="2px"></th>';
		$tablar .= '</tr>';
		$tablar .= '<tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>';
	  	$tablar .= '</table>';
		
		$val[] = array('#locategridresult', $tablar, 'html');
		$evt[] = array('#btnimprimir', 'click','reportes_cajagen();');

		$fun[]= array('var imagen=urljs+"images/calendar.png";
			$("#checkTodos").hide();
			$("#TbPie").hide();
						
			var dates = $( "#txtfecha1, #txtfecha2" ).datepicker({
				defaultDate: "+1w",
				showOn: "both",
				showButtonPanel: true,
				changeMonth: true,
				changeYear:true,
				buttonImage: imagen,
				buttonText:"Seleccione la fecha.",
				buttonImageOnly: true,				
				maxDate: "+0D",
				numberOfMonths: 1,
				onSelect: function( selectedDate ) {
					var option = this.id == "txtfecha1" ? "minDate" : "maxDate",
						instance = $( this ).data( "datepicker" ),
						date = $.datepicker.parseDate(
							instance.settings.dateFormat ||
							$.datepicker._defaults.dateFormat,
							selectedDate, instance.settings );
					dates.not( this ).datepicker( "option", option, date );
				}
		});');
		
		$pintar->IniciaScript();
		$pintar->EjecutarFuncion($fun);
        $pintar->PintarValor($val);
        $pintar->PintarEvento($evt);
        $pintar->FinScript();
    }
    
 	public function listarcierrecajagenAction(){
 	$pintar = new Libreria_Pintar();
    	
	  	if($this->getRequest()->isXmlHttpRequest()){
    		$this->_helper->viewRenderer->setNoRender();
    		$this->_helper->layout->disableLayout();
    		
    		$fecha1 = $this->_request->getPost('fecha1');
    		$fecha2 = $this->_request->getPost('fecha2');
    		$estado= $this->_request->getPost('estado');
    		$cajero = $this->_request->getPost('cajero');
    	
    		$nombrestore = 'integralsmp.dbo.usp_reporte_cierrecajageneral';
    		$parametros[] = array('@fecha1', $fecha1);
    		$parametros[] = array('@fecha2', $fecha2 );
    		$parametros[] = array('@cactivo', $estado);
    		
    		if ($cajero !== 'non'){
    			$parametros[] = array('@codcajero', $cajero);
        		$nombrestore = 'integralsmp.dbo.usp_reporte_cierrecajageneralxcajero';
         		}
    		
    			$datos = new Model_Database_Datos ();
    			$tabla = $datos->ejecutasql ($nombrestore , $parametros , true);

    			$cant = count($tabla);
		    
    		if ($cant>0){
    		
    			$total = 0;
    			$contadorActivos = 0;
    			$contadorAnulados = 0;
    		
    			for($i = 0; $i < $cant; ++$i) {
    				if ($tabla[$i][7] == 'Activo') {
    					$total = $total + $tabla[$i][6];
    					$contadorActivos =$contadorActivos+1 ;
    				}else{
    					$contadorAnulados=$contadorAnulados+1;
    				}
    			}

		  		$val[] = array('#txttotalmontos',number_format($total,"2",".",","),'val');

				//Contar Totales Activos y Anulados
				$val[] = array('#txtrecbscorrectos',$contadorActivos,'val');
				$val[] = array('#txtrecbsanulados',$contadorAnulados,'val');
				$val[] = array('#total',$contadorActivos,'html');
			
				$datacierrecaja = json_encode($tabla);
				
				$cont ='						
					<script type="text/javascript"> var members ='.$datacierrecaja.';</script>
					<script type="text/javascript">
						$(document).ready(function(){
							var optInit = getOptionsCierrecaja();
							$("#Pagination").pagination(members.length, optInit);
						}); 
					</script>
				';
				 	
				echo $cont;
    		
				$pintar->IniciaScript();
			
			
				$evt[]=array('#chkTodos','click','cierrecajagenerallista("non");');
		
				$val[] = array('#cboreportes', '9999999999', 'val');		
			
				if($cajero == 'non'){
				
					$cajeros=$datos->ejecutasql('integralsmp.dbo.usp_reportefiltro_cierrecajageneralcajeros ', $parametros, true);
		        	$cantcaj = count($cajeros);
		        
		        	for($i = 0; $i <$cantcaj ; ++$i){   	
		        	$cbocajeros[] = array($cajeros[$i][0], $cajeros[$i][1]);
		        	}
	
		        $val[] = array('#cbocajeros', $pintar->ContenidoCombo($cbocajeros, '9999999999'), 'html');
		        $evt[] = array('#cbocajeros', 'change', 'cierrecajagenerallista("caj");');
				}		
				
    		}
    		else{
    			$tablar =  '<table class="tabla" >';
				$tablar .= '<tr>';
				$tablar .= '<th width="50px">Item</th>';
				$tablar .= '<th width="50px">Nro.Recibo</th>';
				$tablar .= '<th width="40px">Fecha</th>';
				$tablar .= '<th width="40px">Hora</th>';
				$tablar .= '<th width="280px">Contribuyente</th>';
				$tablar .= '<th width="180px">Cajero</th>';
				$tablar .= '<th>Monto</th>';
				$tablar .= '<th>Estado</th>';
				$tablar .= '<th>Tipo Pago</th>';
				$tablar.=  '<th width="2px"></th>';
				$tablar .= '</tr>';				
				$tablar.='<tr class="cambio" ><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>';
	  			$tablar .='</table>';
		
				$val[] = array('#locategridresult', $tablar, 'html');
				$val[]=array('#Pagination','','html');
    		}
    		$pintar->PintarEvento($evt);			
	        $pintar->PintarValor($val);
	        $pintar->FinScript();  
	  	}
    }
    
    public function detalleanuladoAction(){
       	$pintar = new Libreria_Pintar();

	    	$this->_helper->layout->disableLayout();
	    		
		    $nrorec = $this->_request->getParam('nrorec','');
	    	
	    	$nombrestore = 'integralsmp.dbo.usp_detalle_recibanulado';
	    	$parametros[] = array('@nrorecibo', $nrorec);
	    	
	    	$cn = new Model_Database_Datos();
	    	$result = $cn->ejecutasql($nombrestore, $parametros, false);
	    		    		    	
	    	$val[]=Array('#sptipoanulacion',$result[0][2],'html');
	        $val[]=Array('#detallerec',$result[0][1],'html');
	    	
	    	$pintar->PintarValor($val);
	}

	public function ingresoxpartidaAction(){
		  $pintar = new Libreria_Pintar();  

        $tablar =  '<table class="tabla">';
		$tablar .= '<tr>';
		$tablar .= '<th width="100px">Codigo</th>';
		$tablar .= '<th width="400px">Descripcion</th>';		
		$tablar .= '<th width="100px">Monto</th>';
		$tablar .= '</tr>';
		$tablar .= '<tr class="cambio"><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>';
	  	$tablar .= '</table>';
		
		$val[] = array('#locategridresult', $tablar, 'html');
		
		$fechAct=date("d/m/Y");
		$val[] = array('#txtfecha1parpre',$fechAct , 'val');
		$val[] = array('#txtfecha2parpre',$fechAct , 'val');
	
		for($i = 0; $i < 3; ++$i){
	    	$cboreportes[0] = array('1', '1.Listado Agrupado');
	    	$cboreportes[1] = array('2', '2.Listado Detalle');
	    	$cboreportes[2] = array('3', '3.XLS');
	    }
  
	    $val[] = array('#cboreportesIngresosPresup', $pintar->ContenidoCombo($cboreportes, '9999999999'), 'html');
		$evt[] = array('#btnprocesar', 'click','PartidasPresupuestales();');
		
		$fun[]=array('var imagen=urljs+"images/calendar.png";
		var dates = $( "#txtfecha1parpre, #txtfecha2parpre" ).datepicker({
			defaultDate: "+1w",
			currentText: "Hoy",
			showOn: "both",
			showButtonPanel: true,
			changeMonth: true,
			buttonImage: imagen,
			buttonText:"Seleccione la fecha.",
		    buttonImageOnly: true,
		    maxDate: "+0D",
			changeMonth: true,
			changeYear:true,
			numberOfMonths: 1,
			onSelect: function( selectedDate ) {
				var option = this.id == "txtfecha1parpre" ? "minDate" : "maxDate",
					instance = $( this ).data( "datepicker" ),
					date = $.datepicker.parseDate(
						instance.settings.dateFormat ||
						$.datepicker._defaults.dateFormat,
						selectedDate, instance.settings );
				dates.not( this ).datepicker( "option", option, date );
			}
		});');
		
				
		$evt[] = array('#btnimprimir', 'click','reportesIngresoxpartida();');
		
		$pintar->IniciaScript();
        $pintar->PintarValor($val);
        $pintar->PintarEvento($evt);
        $pintar->EjecutarFuncion($fun);
        $pintar->FinScript();
		
	}
	
	public function generarpartipresupAction(){
		$pintar = new Libreria_Pintar(); 
		
	  	if($this->getRequest()->isXmlHttpRequest()){
    		$this->_helper->viewRenderer->setNoRender();
    		$this->_helper->layout->disableLayout();
    		
			$fecha1 = $this->_request->getPost('fecha1parpre');
			$fecha2=$this->_request->getPost('fecha1parpre');

			$nombrestore = 'integralsmp.dbo.partidas_presup_total';
			$parametros[] = array('@fh1',$fecha1 );
			$parametros[] = array('@fh2',$fecha2 );

			$datos = new Model_Database_Datos ();
			$tabla = $datos->ejecutasql ($nombrestore , $parametros, true);
			$cant = count($tabla);
			$total = 0;
			
			if ($cant>0){	
				for($i = 0; $i < $cant; ++$i) {
					$total = $total + $tabla[$i][2];
				}

				$val[] = array('#txttotalmontos',number_format($total,"2",".",","),'val');	
		
				$dataPartiPresup = json_encode($tabla);
				
				$cont ='						
					<script type="text/javascript"> var members ='.$dataPartiPresup.'</script>
					<script type="text/javascript">
						$(document).ready(function(){
							var optInit = getOptionsPartiPresup();
							$("#Pagination").pagination(members.length, optInit);
						}); 
					</script>
				';
							
				
			
				$nombrestore2  = 'integralsmp.dbo.montocajad_total';
				$parametros2[] = array('@fecha1',$fecha1 );
				$parametros2[] = array('@fecha2',$fecha2 );
				
				$datosCajaTotal = new Model_Database_Datos();
				$tablaMont = $datosCajaTotal->ejecutasql ($nombrestore2 , $parametros2, true); 
				$val[] = array('#txttotalmontosbruto',number_format($tablaMont[0][0],"2",".",","),'val');	
				
			}else{
				$tablar =  '<table class="tabla">';
				$tablar .= '<tr>';
				$tablar .= '<th width="100px">Codigo</th>';
				$tablar .= '<th width="400px">Descripcion</th>';		
				$tablar .= '<th width="100px">Monto</th>';
				$tablar .= '</tr>';
				$tablar.='<tr class="cambio"><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>';
				$tablar .='</table>';
	  	
				$val[] = array('#locategridresult', $tablar, 'html');
    	
			}
			$val[] = array('#total',$cant,'html');    
	  	}

	  	$pintar->IniciaScript();
        $pintar->PintarValor($val);
      
        $pintar->FinScript();
        echo $cont;
	}
	
	public function ingresoxpartidaxareaAction(){
		$pintar = new Libreria_Pintar();  

        $tablar  = '<table class="tabla">';
		$tablar .= '<tr>';
		$tablar .= '<th width="50px">Cod. Servicio</th>';
		$tablar .= '<th width="500px">Descripci&oacute;n</th>';
		$tablar .= '<th width="50px">Monto</th>';				
		$tablar .= '</tr>';
		$tablar .= '<tr class="cambio"><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>';
	  	$tablar .='</table>';
		
		$val[] = array('#locategridresult', $tablar, 'html');
		
		$nombrestore='integralsmp.dbo.[usp_mostrar_areas]';
    	$parametros='';
		
		$datos = new Model_Database_Datos ();
    	$tabla = $datos->ejecutasql ($nombrestore , $parametros, false);
    	$cant = count($tabla);
    	
    	if ($cant>0) {
    		for($i = 0; $i < $cant; ++$i){
				$cboareas[$i] = array($tabla[$i][0],$tabla[$i][1]);  	
	        }	    
			$val[] = array('#cboareas', $pintar->ContenidoCombo($cboareas, '9999999999'), 'html');
    	}
    	
	    $evt[] = array('#btnBuscar', 'click','serviciosxareaconsulta();');
	   
	    $fechAct=date("d/m/Y");
		$val[] = array('#txtfecha1parprearea',$fechAct , 'val');
		$val[] = array('#txtfecha2parprearea',$fechAct , 'val');
	    
	    for($i = 0; $i < 2; ++$i){
	    	$cboreportes[0] = array('1', '1.PDF');
	    	$cboreportes[1] = array('2', '2.XLS');
	    }
	    
	    $val[] = array('#cboreportesIngresosPresupArea', $pintar->ContenidoCombo($cboreportes, '9999999999'), 'html');

	    $fun[]= array('var imagen=urljs+"images/calendar.png";
			var dates = $( "#txtfecha1parprearea, #txtfecha2parprearea" ).datepicker({
				defaultDate: "+1w",
				showOn: "both",
				showButtonPanel: true,
				changeMonth: true,
				changeYear:true,
				buttonImage: imagen,
				buttonText:"Seleccione la fecha.",
				buttonImageOnly: true,
				maxDate: "+0D",
				changeMonth: true,
				numberOfMonths: 1,
				onSelect: function( selectedDate ) {
					var option = this.id == "txtfecha1parprearea" ? "minDate" : "maxDate",
						instance = $( this ).data( "datepicker" ),
						date = $.datepicker.parseDate(
							instance.settings.dateFormat ||
							$.datepicker._defaults.dateFormat,
							selectedDate, instance.settings );
					dates.not( this ).datepicker( "option", option, date );
				}
		});');	    
	    
		$evt[]=array('#btnimprimir','click','reportesIngresosxPartidaxArea();');
	    
		$pintar->IniciaScript();
        $pintar->PintarValor($val);
        $pintar->PintarEvento($evt);
        $pintar->EjecutarFuncion($fun);
        $pintar->FinScript();
	}
	
	public function partidaprepxareAction(){
		$pintar = new Libreria_Pintar();
		
	  	if($this->getRequest()->isXmlHttpRequest()){
    		$this->_helper->viewRenderer->setNoRender();
    		$this->_helper->layout->disableLayout();

			$codarea=$this->_request->getPost('areas');	
			$fecha1 = $this->_request->getPost('fecha1');
			$fecha2 = $this->_request->getPost('fecha2');

			$nombrestore  = 'integralsmp.dbo.usp_serviciosxarea';
			$parametros[] = array('@codarea',$codarea);
			$parametros[] = array('@fecha1',$fecha1 );
			$parametros[] = array('@fecha2',$fecha2 );
				
			$datos = new Model_Database_Datos();
			$tabla = $datos->ejecutasql ($nombrestore , $parametros, true);
			$cant = count($tabla); 
			$total = 0;  
		
			if ($cant>0){
			
				for($i = 0; $i < $cant; ++$i) {
					$total = $total + $tabla[$i][2];
				}
		
				$val[] = array('#txttotalmontos',number_format($total,"2",".",","),'val');	

				$dataPartiPresupArea = json_encode($tabla);
				$cont ='						
					<script type="text/javascript"> var members ='.$dataPartiPresupArea.'</script>
					<script type="text/javascript">
						$(document).ready(function(){
							var optInit = getOptionsPartiPresupArea();
							$("#Pagination").pagination(members.length, optInit);
						}); 
					</script>
				';
							
				echo $cont;
				  
			}else{
				 $tablar =  '<table class="tabla">';				 
				 $tablar .= '<tr>';
				 $tablar .= '<th width="50px">Cod. Servicio</th>';
				 $tablar .= '<th width="500px">Descripci&oacute;n</th>';
				 $tablar .= '<th width="50px">Monto</th>';				
				 $tablar .= '</tr>';
				 $tablar.='<tr class="cambio"><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>';
				 $tablar .='</table>';	 		
				 
				 $val[] = array('#locategridresult', $tablar, 'html');
			}
	  	}
	  	$val[] = array('#total',$cant,'html');

	  	$pintar->IniciaScript();
        $pintar->PintarValor($val);
        $pintar->FinScript();
	}
	
	public function tipoingresoAction(){
		$pintar = new Libreria_Pintar();  

        $tablar =  '<table class="tabla">';
		$tablar .= '<tr>';
		$tablar .= '<th width="50px">Codigo</th>';
		$tablar .= '<th width="400px">Nombre</th>';
		$tablar .= '<th width="50px">Nro. Recibo</th>';		
		$tablar .= '<th width="100px">Fec.Pago</th>';
		$tablar .= '<th width="50px">Monto</th>';
		$tablar .= '</tr>';
		$tablar .= '<tr class="cambio"><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>';
	  	$tablar .= '</table>';
		
		$val[] = array('#locategridresult', $tablar, 'html');
		
		$fechAct=date("d/m/Y");
		$val[] = array('#txtfecha1tipingr',$fechAct , 'val');
		$val[] = array('#txtfecha2tipingr',$fechAct , 'val');
	    
		$nombrestore='mostrar_pagos';
		$parametros='';
		$datos=new Model_Database_Datos();
		$tabla=$datos->ejecutasql($nombrestore,$parametros, false);
		$cant=count($tabla);
		
		for ($i=0; $i<$cant;$i++){
			$cbotipingresos[$i]=array($tabla[$i][0],$tabla[$i][1]);
			$val[]=array('#cboTipoIngresos',$pintar->ContenidoCombo($cbotipingresos,'9999999999'),'html');	
		}

		for($i = 0; $i < 1; ++$i){
	    	$cboreportes[0] = array('1', '1.XLS');
	    }
      
	    $val[] = array('#cboreportesTipoIngresos', $pintar->ContenidoCombo($cboreportes, '9999999999'), 'html');
		$evt[] = array('#btnprocesar', 'click','TipoIngreso();');
		$fun[]=array('var imagen=urljs+"images/calendar.png";
			
		var dates = $( "#txtfecha1tipingr, #txtfecha2tipingr" ).datepicker({
			defaultDate: "+1w",
			showOn: "both",
			showButtonPanel: true,
			changeMonth: true,
			buttonImage: imagen,
			buttonText:"Seleccione la fecha.",
		    buttonImageOnly: true,		    
		    maxDate: "+0D",
			changeMonth: true,
			changeYear:true,
			numberOfMonths: 1,
			onSelect: function( selectedDate ) {
				var option = this.id == "txtfecha1tipingr" ? "minDate" : "maxDate",
					instance = $( this ).data( "datepicker" ),
					date = $.datepicker.parseDate(
						instance.settings.dateFormat ||
						$.datepicker._defaults.dateFormat,
						selectedDate, instance.settings );
				dates.not( this ).datepicker( "option", option, date );
			}
		});');
		
	    $fun[]= array('$("#tbpie").hide();');
		$evt[] = array('#btnimprimir', 'click','reportesTipIngreso();');
		
		$pintar->IniciaScript();
        $pintar->PintarValor($val);
        $pintar->PintarEvento($evt);
        $pintar->EjecutarFuncion($fun);
        $pintar->FinScript();
	}
	
	public function detallereciboAction(){
		$pintar = new Libreria_Pintar(); 
		
	  	if($this->getRequest()->isXmlHttpRequest()){
    		$this->_helper->viewRenderer->setNoRender();
    		$this->_helper->layout->disableLayout();
    		
			$fecha1 = $this->_request->getPost('fecha1');
			$fecha2 = $this->_request->getPost('fecha2');
			$tippago=$this->_request->getPost('tippago');

			$nombrestore = 'integralsmp.dbo.detallerecib';
			$parametros[] = array('@fecha1',$fecha1);
			$parametros[] = array('@fecha2',$fecha2);
			$parametros[] = array('@tippag',$tippago );
    	
			$datos = new Model_Database_Datos ();
			$tabla = $datos->ejecutasql ($nombrestore , $parametros, true);
			$cant = count($tabla);
		  
			if ($cant>0){
				$total=0;	
				for($i=0;$i<$cant;$i++){
					$total=$total+$tabla[$i][4];
				}

				$val[]=array('#txttotalmontos',number_format($total,"2",".",","),'val');
					
				$dataTipoIngreso = json_encode($tabla);
				$cont ='						
					<script type="text/javascript"> var members ='.$dataTipoIngreso.'</script>
					<script type="text/javascript">
						$(document).ready(function(){
							var optInit = getOptionsTipIngreso();
							$("#Pagination").pagination(members.length, optInit);
						}); 
					</script>
				';
						
				echo $cont;
			}else{
				$tablar =  '<table  class="tabla">';
				$tablar .= '<thead>';
				$tablar .= '<tr>';
				$tablar .= '<th width="50px">Codigo</th>';
				$tablar .= '<th width="400px">Nombre</th>';
				$tablar .= '<th width="50px">Nro. Recibo</th>';		
				$tablar .= '<th width="100px">Fec.Pago</th>';
				$tablar .= '<th width="50px">Monto</th>';
				$tablar .= '</tr>';
				$tablar .= '</thead>';
				$tablar.='<tr class="cambio"><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>';
				$tablar .='</table>';
				
				$val[] = array('#locategridresult', $tablar, 'html');
				
			}
			$val[] = array('#total',$cant,'html');    
	  	}
		    
	  	$pintar->IniciaScript();
        $pintar->PintarValor($val);
        $pintar->FinScript();
	}
	
	/******/
	
	/** Made by Hernan Sulla **/
	public function servcontribAction(){
		$pintar=new Libreria_Pintar();
    	$evt[]=array('#btnProcesar','click','vistacontri();');
    	$evt[]=array('#btnImprimir','click','reportes("hernan sulla");');	
    	$evt[]=array('#cbOption','change','textoscontri("s");');
    	$evt[]=array('#cbEstado','change','vistacontri();');
    	
	    $val[]= array('#txtFecha1',date("d/m/Y"),'val');
	    $val[]= array('#txtFecha2',date("d/m/Y"),'val');
	    //$val[]= array('#cbEstado','disable','disable');
	    $evt[]=array('#txtCodigo','keypress','return presscodigo(event);');
	    
    	$pintar->IniciaScript();
    	$pintar->PintarEvento($evt);
    	$pintar->PintarValor($val);
    	$pintar->FinScript();
	}
	
	public function servmostrarcontribAction(){
		$corre=0;
    	$mal=0;
    		
    	if($this->getRequest()->isXmlHttpRequest()){
    		$this->_helper->viewRenderer->setNoRender();
    		$this->_helper->layout->disableLayout();
    	
    		$cod = $this->_request->getPost('codigo');
    		$fecha1 = $this->_request->getPost('fecha1');
    		$fecha2 = $this->_request->getPost('fecha2');
    		$estado = $this->_request->getPost('cboest');
    		$cbop=$this->_request->getPost('cbop');
    		$dato1=$this->_request->getPost('vari');
    		
    		$datos = new Model_Database_Datos();
 			if ($cbop==3 || $cbop==5){
	    		$parametros[]=array('@fx',$cbop);
	    		$parametros[]=array('@ccontri',$cod);
	    		$parametros[]=array('@dfec1',$fecha1);
	    		$parametros[]=array('@dfec2',$fecha2);
	    		$parametros[]=array('@dato1',$dato1);
 			}else{
 				$parametros[]=array('@fx','1');
	    		$parametros[]=array('@ccontri',$cod);
	    		$parametros[]=array('@dfec1',$fecha1);
	    		$parametros[]=array('@dfec2',$fecha2);
 			}
    	
			$tabla = $datos->ejecutasql('integralsmp.dbo.pxrecibos_her', $parametros, true);
			$cant = count($tabla);

			$arregloa = null;
			
			for ( $i = 0; $i < $cant; ++$i){
				$arreglox = null;
				if($tabla[$i][2]=="A"){$mal++;}
				
				for($j = 0; $j < count($tabla[$i]); ++$j){
					$arreglox[$j] = $tabla[$i][$j];
				}
				
				if($estado == 't'){
					$arregloa[] = $arreglox;
				}else{
					if($tabla[$i][2] == $estado and $tabla[$i][2] != " "){
						$arregloa[] = $arreglox;
					}
					if($tabla[$i][2] == $estado and $tabla[$i][2] !="A"){
						$arregloa[] = $arreglox;
					}
				}		
			}

    		$dataserv = json_encode($arregloa);

			$cont ='						
					<script type="text/javascript"> var members ='.$dataserv.'; </script>
					<script type="text/javascript"> var sestado ="'.$estado.'"; </script>
					<script type="text/javascript">
						$(document).ready(function(){
							var optInit = getOptionsServ("1");
							$("#Pagination").pagination(members.length, optInit);
						}); 
					</script>
			';
			
			$datos1=new Model_Database_Datos();
    		$param[]=array('@ccontri',$cod);
    		$tabla1 = $datos1->ejecutasql('integralsmp.dbo.px_busca_contri_her', $param, true);
			
			$pintar=new Libreria_Pintar();
			$val[]=array('#txtCorrectos',$cant-$mal,'val');
			$val[]=array('#txtAnulados',$mal-0,'val');
			if($cod != '000000' and $cod != '--' ){
				$val[]=array('#txtnombre',$tabla1[0][1],'val');
				$val[]=array('#txtvari',$tabla1[0][2],'val');
			}
			$pintar->IniciaScript();
			$pintar->PintarValor($val);
			$pintar->FinScript();
			echo $cont;
			
			
    		if($cant>0 ){
				$func[]=array('$("#btnImprimir").removeAttr("disabled","disabled");');	
    		}else{
				echo "no se encontraron datos";
				$func[]=array('$("#Pagination").html("");');
				$func[]=array('$("#btnImprimir").attr("disabled","disabled");');
				$func[]=array('$("#cbEstado").attr("disabled","disabled");');
    		}
    		
    		$pintar = new Libreria_Pintar();
    		$pintar->IniciaScript();
    		$pintar->EjecutarFuncion($func);
    		$pintar->FinScript();
    	}
	}
	
	public function servdetalleAction(){
		$this->_helper->layout->disableLayout();
		
		$nurec= $this->_request->getParam('nurec','');
		$tbl= $this->_request->getParam('tbl','');
		$contri= $this->_request->getParam('contri','');
		$cajero= $this->_request->getParam('cajero','');
		$numcaja= $this->_request->getParam('numcaja','');
		
		$total=0;
		
		$datos = new Model_Database_Datos();	
		$parametros[]=array('@cnumrec',$nurec);
		$parametros[]=array('@tbl',$tbl);	
		$parametros[]=array('@ccontri',$contri);
		
		$tabla = $datos->ejecutasql ( 'integralsmp.dbo.pxDetRecibos', $parametros, false);
		$cant = count ( $tabla ); 

		
		$tablahCa = '<table class="tabla" >';
		$tablahCa .= '<tr >';
		$tablahCa .= '<th width="270">Tributo</th>';
		$tablahCa .= '<th width="70">Periodo</th>';
		$tablahCa .= '<th width="70">Monto</th>';
		$tablahCa .= '<th width="70">Dscto</th>';
		$tablahCa .= '<th width="70">Monto Dscto</th>';
		$tablahCa .= '<th width="70">Gasto</th>';
		$tablahCa .= '<th width="70">Interes</th>';
		$tablahCa .= '<th width="70">Total</th>';
		$tablahCa .= '</tr>';
		$tablahCa .= '</table>';
		
		$tablah = '<table  class="tabla">';
			
		for($i = 0; $i < $cant; ++ $i) {
			$tablah .= '<tr>';
			$tablah .= '<td width="250">' . $tabla[$i][3] .'</td>';
			$tablah .= '<td width="70" align="center" >' . $tabla[$i][6] . '</td>';
			$tablah .= '<td width="70" align="center" >' . $tabla[$i][7].'</td>';
			$tablah .= '<td width="70" align="center" >' . $tabla[$i][9].'</td>';
			$tablah .= '<td width="70" align="center" >' . ($tabla[$i][7] - $tabla[$i][9]). '</td>';
			$tablah .= '<td width="70" align="center" >' . $tabla[$i][8] . '</td>';
			$tablah .= '<td width="70" align="center" >' . $tabla[$i][11] . '</td>';
			$tablah .= '<td width="70" align="center">' . $tabla[$i][13] . '</td>';
			$tablah .= '</tr>';
			$total = $total + $tabla[$i][13];
		}
			
		$tablah .= '</table>';
		
		$cabecera ='<strong>Detalle de Recibo Nro : '.$nurec.'</strong><br>';
		$boton ='<button id="btnImprimir" >';
		$boton .='Imprimir Constancia';
		$boton .='</button>';

		$letras=new Libreria_Numerosletras();
		
		$letrasTotal=$letras->num2letras($total);
		$val[]=array('#cabeTabla',$tablahCa,'html');
		
		$val[]=array('#detalleReci',$tablah,'html');
		
		$val[]=array('#locatetotal', $total.'<br>'.$letrasTotal.' Nuevos Soles', 'html');
		$val[]=array('#cabecera', $cabecera, 'html');
		$val[]=array('#verConstancia', $boton, 'html');
		$evt[]=array('#verConstancia', 'click', 'reportconstancia("'.$tabla[0][4].'","'.$tabla[0][0].'","'.$nurec.'","'.$tbl.'","'.$letrasTotal.'","'.$cajero.'","'.$numcaja.'","Administrador");');
		$pintar=new Libreria_Pintar();
		
		$pintar->IniciaScript();
		$pintar->PintarValor($val);
		$pintar->PintarEvento($evt);
		$pintar->FinScript();
	}
	
	public function liscontriAction(){
		$this->_helper->layout->disableLayout();
		$nombre=$this->_request->getParam('nombre','');
		
		$dato=new Model_Database_Datos();
		$parametros[]=array('@ncontri',$nombre);
		
		$tabla=$dato->ejecutasql('integralsmp.dbo.uspw_buscontribuyente',$parametros, true);
		$cant=count($tabla);
		$dataserv = json_encode($tabla);

		$cont ='						
			<script type="text/javascript"> var members ='.$dataserv.'; </script>
			<script type="text/javascript"> var sestado ="09"; </script>
			<script type="text/javascript">
				$(document).ready(function(){
					var optInit = getOptionsServ("9");
					$("#Pagination1").pagination(members.length, optInit);
				}); 
			</script>
		';
		
		echo $cont;
		$val[]=array('#total','<br><h3> Total :'.$cant.'</h3>','html');	
		$pintar=new Libreria_Pintar();
		$pintar->IniciaScript();
		$pintar->PintarValor($val);
		$pintar->FinScript();
	}
	
	/*******/
	public function ingresosxservxinsolutoAction(){
			$pintar=new Libreria_Pintar();
		     
			$fechAct=date("Y");
			
			$tablon='<table class="tabla">';
			$tablon.='<tr>';
			$tablon.='<th>Nro. </th>';
			$tablon.='<th>Nro.Recibo</th>';
			$tablon.='<th width="300px;">Nombre</th>';
			$tablon.='<th>Imp.Predial '.$fechAct.'</th>';
			$tablon.='<th>Imp.Predial Anteriores</th>';
			$tablon.='<th>Arbitrios '.$fechAct.'</th>';
			$tablon.='<th>Arbitrios Anteriores</th>';
			$tablon.='</tr>';
			$tablon.='<tr><td>&nbsp;<td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>';
			
			
			
			$fun[]= array('var imagen=urljs+"images/calendar.png";				
			var dates = $( "#txtfechaserin1, #txtfechaserin2" ).datepicker({
				defaultDate: "+1w",
				showOn: "both",
				showButtonPanel: true,
				changeMonth: true,
				changeYear:true,
				buttonImage: imagen,
				buttonText:"Seleccione la fecha.",
				buttonImageOnly: true,
				minDate: new Date(2009,01,01),
				maxDate: "+0D",
				numberOfMonths: 1,
				onSelect: function( selectedDate ) {
					var option = this.id == "txtfecha1" ? "minDate" : "maxDate",
						instance = $( this ).data( "datepicker" ),
						date = $.datepicker.parseDate(
							instance.settings.dateFormat ||
							$.datepicker._defaults.dateFormat,
							selectedDate, instance.settings );
					dates.not( this ).datepicker( "option", option, date );
				}
		   });');
			
			$val[]=array('#locategridresult',$tablon,'html');
			
			$pintar->IniciaScript();
			$pintar->PintarValor($val);
			$pintar->EjecutarFuncion($fun);
			
			$pintar->FinScript();
		
	}
	
public function listaingresoAction(){
 	
 	$func[]=array('Datepiked("#txtFecha1");');
 	$func[]=array('Datepiked("#txtFecha2");');
 	
 	$comp[]=array('#btnExportar',false);
 	//btnExportar
	$evt[]=array('#btnExportar','click','exportaringresoanual()');
 	$evt[]=array('#btnProcesar','click','Procesar_ingr()');
 	
 	$pintar=new Libreria_Pintar();
 	$pintar->EjecutarFuncion($func);
 	$pintar->PintarEvento($evt);
 	$pintar->HabilitarComponente($comp);
 	    
    }
    
    
    public function mostrarinformeAction(){
    if($this->getRequest()->isXmlHttpRequest()){
    		$this->_helper->viewRenderer->setNoRender();
    		$this->_helper->layout->disableLayout();
    		
    		$fecha1 = $this->_request->getPost('fecha1');
    		$fecha2 = $this->_request->getPost('fecha2');
    
    		$parametros[]=array('@fecha1',$fecha1);
    		$parametros[]=array('@fecha2',$fecha2);
    		$datos = new Model_Database_Datos();
    		$pintar=new Libreria_Pintar();
    		$comp[]=array('#btnExportar',false);
 			$pintar->HabilitarComponente($comp);
    		
    		$tabla = $datos->ejecutasql('usp_lista_ingreso_teso',$parametros);
    
    		if(count($tabla)==0){	
    		echo '<center><b>No hay datos para mostrar...</b></center>';
    		return;
    		}
    		
    		$comp[]=array('#btnExportar',true);
 			$pintar->HabilitarComponente($comp);
 			
    		$json=json_encode($tabla);
    		
    		$Json = json_encode($tabla);
			$cont1 ='						
					<script type="text/javascript"> 
						$(document).ready(function(){
						llenar_resul('.$Json.')
						}); 
					</script>
			';
			echo $cont1;	
    		
    }
    
    }
}

